import cache from "@/assets/js/cache"
export default {
    powerList: [],
    cacheKey: "/power/list",
    cacheSet() {
        cache.set(this.cacheKey, this.powerList)
    },
    cacheGet() {
        let data = cache.get(this.cacheKey)
        if (Object.prototype.toString.call(data) !== "[object Array]") return
        this.powerList = data
    },
    set(itemArray) {
        this.powerList = []
        if (Object.prototype.toString.call(this.powerList) !== "[object Array]")
            return
        this.powerList = itemArray
        this.cacheSet()
    },
    check(path) {
        if (!this.powerList ||
            Object.prototype.toString.call(this.powerList) !== "[object Array]" ||
            this.powerList.length <= 0
        ) {
            this.cacheGet()
        }
        // console.log(this.powerList)
        return this.powerList.includes(path)
    },
}